import { request } from '@/utils/http'

export interface sendCodeType {
    phone: number | string
}

export function sendCode(data: sendCodeType) {
    return request.http({
        url: '/api/t.sms/sendCode',
        data
    })
}

// 上传图片
export function uploadFile(file: any) {
    let url = ''
    // #ifdef APP-PLUS
    url = import.meta.env.VITE_APP_BASE_URL
    // #endif
    // #ifdef H5
    url = import.meta.env.VITE_APP_BASE_PRE
    // #endif
    return new Promise((resolve, reject) => {
        uni.uploadFile({
            url: `${url}/api/resources/upload`,
            filePath: file,
            name: 'file',
            success: (res) => {
                resolve(JSON.parse(res.data))
            },
            fail: (res) => {
                reject(res)
            }
        })
    })
}

// 根据 KEY 获取对应数据
export function getKeyData(key: string) {
    return request.http({
        url: '/api/t.systemData/getCategoryByKey',
        data: { key: key }
    })
}

// 根据 KEY 获取对应系统设置
export function getKeySetting(key: string) {
    return request.http({
        url: '/api/t.systemData/getSettingByKey',
        data: { key: key }
    })
}

// 获取无限极分类数据
export function getCategoryData() {
    return request.http({
        url: '/api/t.systemData/categoryTree'
    })
}

// 意见反馈
export interface feedbackType {
    type: useType
    category_id: number
    content: string
    image?: string
    contact_information: string
}

export function feedback(data: feedbackType) {
    return request.http({
        url: '/api/t.feedback/add',
        data
    })
}

// 购买支付接口
export function pay(data: { policy_id: number; uid: number; pay_amount: number; version: string }) {
    return request.http({
        url: '/api/t.notify/buyAgentPolicyNotify',
        data
    })
}

// 直采列表
export function voucherQuery() {
    return request.http({
        url: '/api/d.pickGiftBag/query'
    })
}

// 直采支付
export function voucherPay(data: { id: number }) {
    return request.http({
        url: '/api/d.pickGiftBag/buy',
        data
    })
}
